package com.free.md5parser.task;

import cn.hutool.core.io.FileUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.io.File;

@Slf4j
@Component
public class ClearFileTask {

    @Value("${temp.dir:/data}")
    private String tempDir;

    @Scheduled(cron = "0 0 0 5 * ?")
    public void clearTask() {
        log.info("开始清理文件......");
        File fileDir = new File(getFileDirPath());
        if (fileDir.exists()) {
            FileUtil.clean(fileDir);
        }
        log.info("结束清理文件");
    }

    private String getFileDirPath() {
        return tempDir + "/file";
    }
}
